<?php

namespace app\common\service;

use app\common\job\DouyinMiniProgramMessage;
use app\common\model\Member;
use think\facade\Queue;

/**
 * 抖音小程序订阅消息
 * Class DouyinMiniProgramMessageService
 * @package app\common\service
 */
class DouyinMiniProgramMessageService implements SubscribeMessageService
{

    /**
     * 律师回复咨询问题
     * @param $memberId
     * @param $content
     * @param $lawyerName
     * @param $time
     * @return void
     */
    public function messageLawyerFirstReplay($memberId, $content, $lawyerName, $time)
    {
        $openid = Member::where('id', $memberId)->value('openidDouyin');
        if (is_blank($openid)) {
            return;
        }

        $tpl_id = 'MSG130123491eb9c46b2d0d59bc4845cf765702e4b14572';

        $data = [
            '回复内容' => mb_substr($content, 0, 20),
            '备注' => $lawyerName . '律师' . date('Y年m月d日 H:i:s', $time) . '回复了您的问题，点击查看详情'
        ];
        $page = 'pages/user/user?idx=3';

        $this->pushMessage($openid, $tpl_id, $data, $page);
    }

    /**
     * 提醒用户评价
     * @param $memberId
     * @param $content
     * @param $lawyerName
     * @return void
     */
    public function messageRemindComment($memberId, $content, $lawyerName)
    {
        $openid = Member::where('id', $memberId)->value('openidDouyin');
        if (is_blank($openid)) {
            return;
        }

        $tpl_id = 'MSG13012341b59dfb5de989acc031f01c7ea0b260914569';

        $data = [
            '订单名称' => mb_substr($content, 0, 20),
            '备注' => '您在熊猫法律咨询发起的咨询已完成，律师解答不易，评价鼓励一下ta吧！'
        ];
        $page = 'pages/user/user?idx=3';

        $this->pushMessage($openid, $tpl_id, $data, $page);

    }

    private function pushMessage($openid, $tpl_id, $data, $page)
    {
        $job_data = [
            'openid' => $openid,
            'tpl_id' => $tpl_id,
            'data' => $data,
            'page' => $page,
        ];
        //
        Queue::push(DouyinMiniProgramMessage::class, $job_data);
    }

    public function getConsultingTemplates(): array
    {
        return [
            'MSG130123491eb9c46b2d0d59bc4845cf765702e4b14572',
            'MSG13012341b59dfb5de989acc031f01c7ea0b260914569',
        ];
    }
}